package com.ysy.tz.core.selfcomp;

import com.ysy.tz.core.event.BizEvent;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.function.Consumer;
import javafx.beans.binding.Bindings;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import org.apache.commons.lang3.StringUtils;

public class NodeTableColumn extends TableColumn {
    private ObjectProperty<NodeTableButtons> buttons = new SimpleObjectProperty();
    private ArrayList<NodeTableButtons> buttonsArrayList = new ArrayList();
    private Consumer<BizEvent> action;

    public NodeTableColumn() {
        this.setCellFactory((tableColumn) -> {
            TableCell<Object, Object> cell = new TableCell<Object, Object>() {
                protected void updateItem(Object item, boolean empty) {
                    super.updateItem(item, empty);
                    if (empty) {
                        this.setText((String)null);
                        this.setGraphic((Node)null);
                    } else {
                        try {
                            HBox hBox = new HBox();
                            hBox.setSpacing(8.0);
                            hBox.setAlignment(Pos.CENTER);
                            Iterator var4 = NodeTableColumn.this.buttonsArrayList.iterator();

                            while(var4.hasNext()) {
                                NodeTableButtons nodeTableButton = (NodeTableButtons)var4.next();
                                Button button = new Button();
                                button.setText(nodeTableButton.getText());
                                if (StringUtils.isNotBlank(nodeTableButton.getStyle())) {
                                    button.setStyle(nodeTableButton.getStyle());
                                }

                                if (StringUtils.isNotBlank(nodeTableButton.getTextFill())) {
                                    button.setTextFill(Color.valueOf(nodeTableButton.getTextFill()));
                                    button.textFillProperty().bind(Bindings.when(button.pressedProperty()).then(Color.valueOf("#000000")).otherwise(Color.valueOf(nodeTableButton.getTextFill())));
                                }

                                button.setOnAction((actionEvent) -> {
                                    BizEvent bizEvent = new BizEvent(nodeTableButton.getOpeType(), this.getTableRow().getItem());
                                    System.out.println("--------->>>点击了删除--->>> " + bizEvent.getData());
                                    if (NodeTableColumn.this.action != null) {
                                        NodeTableColumn.this.action.accept(bizEvent);
                                    }

                                });
                                hBox.getChildren().add(button);
                            }

                            this.setGraphic(hBox);
                        } catch (Exception var7) {
                            var7.printStackTrace();
                        }
                    }

                }
            };
            return cell;
        });
    }

    public NodeTableButtons getButtons() {
        return (NodeTableButtons)this.buttons.get();
    }

    public ObjectProperty<NodeTableButtons> buttonsProperty() {
        return this.buttons;
    }

    public void setButtons(NodeTableButtons buttons) {
        this.buttonsArrayList.add(buttons);
        this.buttons.set(buttons);
    }

    public Consumer<BizEvent> getAction() {
        return this.action;
    }

    public void setAction(Consumer<BizEvent> action) {
        this.action = action;
    }
}
